package com.core.website.scheduled;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import static com.core.website.api.LoginApi.heartbeatIpList;


@Component
public class HeartBeatScheduleTask {
    @Scheduled(cron = "0 * * * * ?")
    public void configureTasks() {
        if(heartbeatIpList.keySet().size()>0){
            Calendar now = Calendar.getInstance();
            now.add(Calendar.MINUTE,-5);
            Date time = now.getTime();
            Map<String,Date> map=new HashMap<>();
            for(String key:heartbeatIpList.keySet()){
                Date date = heartbeatIpList.get(key);
                if (date.after(time)) {
                    map.put(key,date);
                }
            }
            heartbeatIpList=map;
        }

    }
}
